package server.session.handler;

import server.session.UserSession;
import unit.request.ChangeInfoRequest;
import unit.request.Request;
import unit.response.ContactInfoChangedMessage;

/**
 * @author Yuri Denison
 * @since 07.08.11
 */
public class ChangeInfoRequestHandler implements RequestHandler {
    @Override
    public void handleRequest(Request request, UserSession userSession) {
        ChangeInfoRequest changeInfoRequest = (ChangeInfoRequest) request;
        userSession.getDataStorage().changeUserInfo(userSession.getUserId(), changeInfoRequest.getProjective(), changeInfoRequest.getNewValues());
        userSession.getCommunicator().send(
                userSession.getDataStorage().getContactList(userSession.getUserId()),
                new ContactInfoChangedMessage(userSession.getSession(), userSession.getUserId(), changeInfoRequest.getProjective(), changeInfoRequest.getNewValues())
        );
    }
}
